<!DOCTYPE html>
<html>

<head>
    {include file='public/meta'/}
</head>

<body>
{include file='public/header'/}
<section>
    <!------------------导航-------------------------->
    {include file='public/left'/}
    <!--------------------------主要内容区域------------------------------------->
    <div class="content">
        <div class="page-heading mgl15 mgr15">
            <ul class="breadcrumb">
                <li>当前位置是:</li>
                <li><a href="javascript:history.back();">商户管理</a></li>
                <li><a href="javascript:history.back();">商户列表</a></li>
                <li class="active" style="color: #02b87f;">门店详情</li>
            </ul>
        </div>
        <div class="mgl15 mgr15">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h4 style="margin:0;font-size:16px;color:#02b87f;">门店名称&nbsp;:&nbsp;<span>{$user.merchant}</span>
                    </h4>
                </div>
            </div>
            <ul id="myTabs" class="nav nav-tabs mgb10">
                <li>
                    <a class="fsz14" href="#Message" data-toggle="tab">基础信息</a>
                </li>
                <li>
                    <a class="fsz14" href="#Cashier" data-toggle="tab">人员列表</a>
                </li>
                <li>
                    <a class="fsz14" href="#Facility" data-toggle="tab">设备列表</a>
                </li>
                <li>
                    <a class="fsz14" href="#ylbset" data-toggle="tab">云喇叭配置</a>
                </li>
                <li>
                    <a class="fsz14" href="#Journal" data-toggle="tab">操作日志</a>
                </li>
            </ul>
            <div id="myTabContent" class="tab-content">
                <div class="tab-pane fade" id="Message">
                    {if condition="checkPath('mach/machxg')"}
                    <div class="col-sm-12 text-right">
                        <a href='{:url("mach/machxg")}?id={$user.id}' class="btn btn-info">修改</a>
                    </div>
                    {/if}
                    <table class="table table-bordered">
                        <caption>基础信息</caption>
                        <tbody>
                        <tr>
                            <td class="active">营业状态</td>
                            <td>{:getmachstatu($user['status'])}</td>
                            <td class="active">创建时间</td>
                            <td>{$user['addtime']|date="Y-m-d H:i:s",###}</td>
                            <td class="active">门店类别</td>
                            <td>{:getlevel($user['leibie'])}</td>
                        </tr>
                        </tbody>
                    </table>
                    <table class="table table-bordered">
                        <caption>代理商信息</caption>
                        <tbody>
                        <tr>

                            <td class="active">代理商名称</td>
                            <td>{:getagent($user['agent'],"name")}</td>
                            <td class="active">业务员</td>
                            <td>{:getsales($user['salesman'])}</td>
                            <td class="active">业务员电话</td>
                            <td>{:getsalestel($user['salesman'])}</td>
                        </tr>
                        </tbody>
                    </table>
                    <table class="table table-bordered">
                        <caption>商户信息</caption>
                        <tbody>
                        <tr>
                            <td class="active">民生商户号</td>
                            <td>{$user['cmmb_mer_id']}</td>
                            <td class="active">微信商户号</td>
                            <td>{$user['sub_mch_id']}</td>
                            <td class="active">支付宝Token</td>
                            <td>{$user['ali_merid']}</td>
                        </tr>
                        <tr>
                            <td class="active">商户联系人</td>
                            <td>{$user['MerchantContent']['contacts']}</td>
                            <td class="active">联系方式</td>
                            <td>{$user['MerchantContent']['tel']}</td>
                            <td class="active">地址</td>
                            <td>{$user['MerchantContent']['address']}</td>
                        </tr>
                        </tbody>
                    </table>

                </div>
                <table class="table table-bordered">
                    <caption>门店费率</caption>
                    <tbody>
                    <tr>
                        <td class="active">微信收款手续费率</td>
                        <td>{$user['wx_service_charge']}‰</td>
                        <td class="active">支付宝收款收款手续费率</td>
                        <td>{$user['ali_service_charge']}‰</td>
                        <td class="active">POS收款手续费率</td>
                        <td>{$user['pos_service_charge']}‰</td>
                    </tr>
                    </tbody>
                </table>

                <!--员工列表-->
                <div class="tab-pane fade" id="Cashier">
                    {if condition="checkPath('personnel/cashieradd')"}
                    <div class="col-sm-12 text-right mgb10">
                        <a href="{:url('personnel/cashieradd')}" class="btn btn-info">添加收银员 </a>
                    </div>
                    {/if}
                    <table class="table table-bordered">
                        <thead>
                        <tr class="active">
                            <th>工号</th>
                            <th>姓名</th>
                            <th>手机号</th>
                            <th>员工角色</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        {volist name="cashier" id="vo"}
                        <tr>
                            <td class="mid">{$vo.gonghao}</td>
                            <td class="mid">{$vo.xingming}</td>
                            <td class="mid">{$vo.tel}</td>
                            <td class="mid">{:getuserlevel($vo['level'])}</td>
                            <td class="mid">
                                {if condition="checkPath('personnel/cashierdel')"}
                                <a href="javascript:;" data-id="{$vo.id}" data-uid="{$vo.uid}"
                                   class="cashierdel btn-link">删除</a>
                                {/if}
                                {if condition="checkPath('personnel/cashieredit')"}
                                <a class="btn-link" href="{:url('Personnel/cashieredit',['id'=>$vo['uid']])}">&nbsp;|&nbsp;&nbsp;详情</a>
                                {/if}
                            </td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
                <!--云喇叭配置-->
                <div class="tab-pane fade" id="ylbset">
                    <form class="form-horizontal adminex-form" action="" method="post"
                          enctype="multipart/form-data">
                        <div class="form-group">
                        <label class="col-sm-2 col-sm-2 control-label">云喇叭设备ID：</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" id="ylb_deviceid" value="{$user['ylb_deviceid']}" name='ylb_deviceid'
                                   placeholder="云喇叭设备ID">
                            <div class="error"></div>
                        </div>
                    </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-sm-2 control-label">云喇叭设备音量：</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="ylb_vol" value="{$user['ylb_vol']}" name='ylb_vol' placeholder="云喇叭设备音量">
                                <div class="error"></div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-primary" onclick="saveylb('bind')">绑定</button>
                            <button type="button" class="btn btn-success" onclick="saveylb('setvol')">调整音量</button>
                            <button type="button" class="btn btn-danger" onclick="saveylb('unbind')">解绑</button>
                        </div>
                    </form>
                </div>

                <!--设备列表-->
                <div class="tab-pane fade" id="Facility">
                    {if condition="checkPath('momach/add_device_micro')"}
                    <div class="col-sm-12 text-right mgb10">
                        <button data-toggle="modal" data-target="#myModal2" type="button" name="Facility" method="post"
                                action="" class="btn btn-info">生成设备码
                        </button>
                    </div>
                    {/if}
                    <table class="table table-bordered">
                        <thead>
                        <tr class="active">
                            <th>设备名称</th>
                            <th>状态</th>
                            <th>绑定码</th>
                        </tr>
                        </thead>
                        <tbody id="tk-tbody">
                        {volist name="devicelist" id="vo"}
                        <tr>
                            <td>{$vo.device_name}</td>
                            <td>
                                {if condition="$vo['status'] eq '1' "}
                                <a href="javascript:;" class="xgbang btn-link" data-id="{$vo.id}" data-toggle="modal"
                                   data-target="#xgbangding">修改密码</a>
                                {else/}
                                未绑定
                                {/if}
                            </td>
                            <td><input type="text" class="form-control copycode" readonly value="{$vo.code}"></td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                    {$devicelist->render()}
                </div>
                <!--操作日志-->
                <div class="tab-pane fade" id="Journal">
                    <table class="table table-bordered">
                        <thead>
                        <tr class="active">
                            <th>日志编号</th>
                            <th>操作人</th>
                            <th>操作类型</th>
                            <th>操作时间</th>
                        </tr>
                        </thead>
                        <tbody>
                        {volist name="czlog" id="vo"}
                        <tr>
                            <td>{$vo.id}</td>
                            <td>{$vo.username}</td>
                            <td>{$vo.log}</td>
                            <td>{$vo['create_time']}</td>
                        </tr>
                        {/volist}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        {include file='public/footer'/}
    </div>
</section>
<!-- 添加设备模态框（Modal） -->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    添加设备
                </h4>
            </div>
            <div class="modal-body">
                <ul id="myTab" class="nav nav-tabs">
                    <li class="active">
                        <a href="#print" data-toggle="tab">
                            打印机
                        </a>
                    </li>
                </ul>
                <div id="myTabContent2" class="tab-content" style="margin-top: 15px;">
                    <div class="tab-pane fade in active" id="print">
                        <form id="frm" class="form-horizontal">
                            <input type="hidden" name="mid" value="{:request()->get('id')}" id="pmid">
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">设备名称：</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id='sbname' name='sbname'>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">打印机用户名：</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id='usernames' name='username'>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">Ukey：</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id='ukey' name='ukey'>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 control-label">SN：</label>
                                <div class="col-sm-10">
                                    <input type="text" class="form-control" id='sn' name='sn'>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" onclick="addprint()">添加</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>

            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<div class="modal fade" id="myModalDevice" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel3">
                    添加微端收银员
                </h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal adminex-form" action="" method="post" id="cashieradd"
                      enctype="multipart/form-data">
                    <div class="form-group" id="ferror5">
                        <label class="col-sm-2 col-sm-2 control-label">姓名</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control ipt4" id="xingming" name="xingming">
                            <div id="error5" class="error"></div>
                        </div>
                    </div>
                    <div class="form-group" id="ferror1">
                        <label class="col-sm-2 col-sm-2 control-label">登入账号</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control ipt4" id="username" name="username">
                            <div id="error1" class="error"></div>
                        </div>
                    </div>
                    <div class="form-group" id="ferror2">
                        <label class="col-sm-2 col-sm-2 control-label">密码</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control ipt4" id="password" name="password">
                            <div id="error2" class="error"></div>
                        </div>
                    </div>
                    <div class="form-group" id="ferror4">
                        <label class="col-sm-2 col-sm-2 control-label">退款密码</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control ipt4" id="tk_password" name="tk_password">
                            <div id="error3" class="error"></div>
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" onclick="adddeviceuser()">
                    提交
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<div class="modal fade" id="myModalDevice_md" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
     aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel6">
                    修改微端收银员
                </h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal adminex-form" action="" method="post" id=""
                      enctype="multipart/form-data">
                    <div class="form-group" id="ferror6">
                        <label class="col-sm-2 col-sm-2 control-label">姓名</label>
                        <div class="col-sm-10">
                            <input type="hidden" name="id" id="id_md" value="">
                            <input type="text" class="form-control ipt4" id="xingming_md" name="xingming">
                            <div id="error6" class="error"></div>
                        </div>
                    </div>
                    <div class="form-group" id="ferror7">
                        <label class="col-sm-2 col-sm-2 control-label">登入账号</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control ipt4" id="username_md" readonly="readonly"
                                   name="username">
                            <div id="error7" class="error"></div>
                        </div>
                    </div>
                    <div class="form-group" id="ferror8">
                        <label class="col-sm-2 col-sm-2 control-label">密码</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control ipt4" id="password_md" name="password">
                            <div id="error8" class="error"></div>
                        </div>
                    </div>
                    <div class="form-group" id="ferror9">
                        <label class="col-sm-2 col-sm-2 control-label">退款密码</label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control ipt4" id="tk_password_md" name="tk_password">
                            <div id="error9" class="error"></div>
                        </div>
                    </div>

                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-primary" onclick="deviceuser_md()">
                    提交
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->

</div>
<!-- 修改绑定退款密码Modal 开始-->
<div class="modal fade" id="xgbangding" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="xgbangdingLabel">绑定收银设备</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="xgbangdingform">
                    <div class="form-group">
                        <label class="col-sm-3 control-label">退款密码：</label>
                        <div class="col-sm-9">
                            <input type="hidden" id="tkid" name="id"/>
                            <input type="text" name="tk_pass" class="form-control" placeholder="请输入密码"/>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" id="xgbingsure">完成</button>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">

    <!--添加设备-->
    function addprint() {
        $.ajax({
            type: "POST",
            url: "{:url('mach/addprint')}",
            async: false,
            data: $('#frm').serialize(),
            success: function (data) {
                if (data.code == 0) {
                    layer.msg("添加成功", {icon: 1});
                    $('#myModal2').modal('hide');
                    setTimeout("window.location.reload()", 500);
                } else {
                    layer.alert(data.message);
                    return false;
                }
            }
        });
    }
    function saveylb(type){
        $.ajax({
            type: "POST",
            url: "{:url('mach/ylbset')}",
            async: false,
            data: {
                'method':type,
                'id':"{$user['id']}",
                'ylb_deviceid':$('#ylb_deviceid').val(),
                'ylb_vol':$('#ylb_vol').val(),
            },
            success: function (data) {
                if (data.code == 0) {
                    layer.msg('处理成功', {icon: 1});
                    // $('#myModal2').modal('hide');
                    // setTimeout("window.location.reload()", 500);
                } else {
                    layer.alert(data.message);
                    return false;
                }
            }
        });
    }

    function adddeviceuser() {
        var mid = {$user['id']};
        var username = $('#myModalDevice #username').val();
        var password = $('#myModalDevice #password').val();
        var tk_password = $('#myModalDevice #tk_password').val();
        var xingming = $('#myModalDevice #xingming').val();
        if (xingming == '') {
            alert('姓名必填');
            return
        }
        if (username == '') {
            alert('登入账号必填');
            return
        }
        if (password == '') {
            alert('密码必填');
            return
        }
        $.ajax({
            type: 'post',
            url: "{:url('Mach/adddeviceuser')}",
            //dataType:"json",
            data: {
                merchid: mid,
                username: username,
                password: password,
                tk_password: tk_password,
                xingming: xingming,
            },
            success: function (data) {

                switch (data) {
                    case 0:
                        alert('添加成功');
                        window.location.reload();
                        break;
                    case 1:
                        alert('添加失败');
                        break;
                    case 2:
                        alert('用户已存在');
                        break;

                }


            }
        })
    }

    function deviceuser_modify(id, xingming, username) {
        $('#myModalDevice_md #id_md').val(id);
        $('#myModalDevice_md #xingming_md').val(xingming);
        $('#myModalDevice_md #username_md').val(username);

        $('#myModalDevice_md').modal('show');

    }

    function deviceuser_md() {
        var id = $('#myModalDevice_md #id_md').val();
        var password = $('#myModalDevice_md #password_md').val();
        var tk_password = $('#myModalDevice_md #tk_password_md').val();
        var xingming = $('#myModalDevice_md #xingming_md').val();
        if (xingming == '') {
            alert('姓名必填');
            return
        }
        $.ajax({
            type: 'post',
            url: "{:url('Mach/deviceuser_md')}",
            //dataType:"json",
            data: {
                id: id,
                password: password,
                tk_password: tk_password,
                xingming: xingming,
            },
            success: function (data) {

                switch (data) {
                    case 0:
                        alert('修改成功');
                        window.location.reload();
                        break;
                    case 1:
                        alert('修改失败');
                        break;
                    case 2:
                        alert('用户已存在');
                        break;

                }
            }
        })
    }

    $(function () {
//        复制绑定码 开始
        $("body").on('click', '.copycode', function (e) {
            $(this).select();
            document.execCommand("Copy"); // 执行浏览器复制命令
            layer.msg("复制成功");
        });
//        复制绑定码结束
        //        页面加载完毕切换tab  开始
        var id = "{:request()->get('id')}";
        var currentTab = "{:request()->get('type')}";
        if (!currentTab) {
            $('#myTabs a[href="#Message"]').tab('show')
        } else {
            if (currentTab == 1) {
                $('#myTabs a[href="#Message"]').tab('show')
            } else if (currentTab == 2) {
                $('#myTabs a[href="#Cashier"]').tab('show')
            } else if (currentTab == 3) {
                $('#myTabs a[href="#Facility"]').tab('show')
            } else if (currentTab == 4) {
                $('#myTabs a[href="#Journal"]').tab('show')
            }
        }
        var reloadUrl = "{:url('mach/machinfo')}?id=" + id + "&type=1";
        var reloadUrl1 = "{:url('mach/machinfo')}?id=" + id + "&type=2";
        var reloadUrl2 = "{:url('mach/machinfo')}?id=" + id + "&type=3";
        var reloadUrl3 = "{:url('mach/machinfo')}?id=" + id + "&type=4";
        $('#myTabs a[href="#Message"]').click(function (e) {
            e.preventDefault()
            window.location.href = reloadUrl;
        });
        $('#myTabs a[href="#Cashier"]').click(function (e) {
            e.preventDefault()
            window.location.href = reloadUrl1;
        });
        $('#myTabs a[href="#Facility"]').click(function (e) {
            e.preventDefault()
            window.location.href = reloadUrl2;
        });
        $('#myTabs a[href="#Journal"]').click(function (e) {
            e.preventDefault()
            window.location.href = reloadUrl3;
        });
        //       页面加载完毕切换tab  jieshu


        //        修改绑定密码 开始
        $("#xgbangding").on('show.bs.modal', function () {
            //                    判断是否有权限修改密码
            var qx = "{:checkPath('mach/device_micro_md_pass')}";
            if (qx == 0) {
                layer.alert("您没有权限进行修改", {icon: 7});
                return false;
            }
            var mid = $(event.target).data("id");
            $("#tkid").val(mid);
        });
        $("#xgbingsure").click(function () {
            $("this").attr("disabled", "disabled");
            $.ajax({
                url: "{:url('mach/device_micro_md_pass')}",
                type: "post",
                data: $("#xgbangdingform").serialize(),
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.message, {icon: 1});
                        setTimeout("window.location.reload()", 1000)
                        return false;
                    } else {
                        layer.alert(data.message);
                        return false;
                    }
                }
            })
        });
//        修改绑定密码 结束
        //        删除员工方法
        $(".cashierdel").click(function (event) {
            event.stopPropagation();
            var id = $(this).attr("data-uid");
            //询问框
            layer.confirm('确认删除该员工吗？', {
                btn: ['确认', '取消'] //按钮
            }, function () {
                $.ajax({
                    url: "{:url('personnel/cashierdel')}",
                    type: "post",
                    async: true,
                    data: {
                        id: id
                    },
                    success: function (data) {
                        if (data.code == 0) {
                            layer.msg("删除成功", {time: 500, icon: 1});
                            setTimeout("window.location.reload()", 500);
                            return false;
                        } else {
                            layer.alert(data.message, {icon: 7});
                            return false;
                        }
                    }
                })
            }, function () {
            });
        });
        //        删除设备方法
        $(".printdel").click(function (event) {
            event.stopPropagation();
            var id = $(this).attr("data-id");
            //询问框
            layer.confirm('确认删除该设备吗？', {
                btn: ['确认', '取消'] //按钮
            }, function () {
                $.ajax({
                    url: "{:url('mach/delprint')}",
                    type: "post",
                    async: true,
                    data: {
                        id: id
                    },
                    success: function (data) {
                        if (data.code == 0) {
                            layer.msg("删除成功", {time: 500, icon: 1});
                            setTimeout("window.location.reload()", 500);
                            return false;
                        } else {
                            layer.alert(data.message, {icon: 7});
                            return false;
                        }
                    }
                })
            }, function () {
            });
        });
    })
</script>

</html>